package com.ruoyi.web.controller.ziran;

import java.util.List;

import com.ruoyi.ziran.domain.ZrPaperUserExcel;
import com.ruoyi.ziran.domain.ZrPaperUserItem;
import com.ruoyi.ziran.service.IZrPaperUserItemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ziran.domain.ZrPaperUser;
import com.ruoyi.ziran.service.IZrPaperUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户答题的试卷Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@Controller
@RequestMapping("/ziran/zrPaperUser")
public class ZrPaperUserController extends BaseController
{
    private String prefix = "ziran/zrPaperUser";

    @Autowired
    private IZrPaperUserService zrPaperUserService;
    @Autowired
    private IZrPaperUserItemService iZrPaperUserItemService;

    //@RequiresPermissions("ziran:zrPaperUser:view")
    @GetMapping()
    public String zrPaperUser()
    {
        return prefix + "/zrPaperUser";
    }

    /**
     * 查询用户答题的试卷列表
     */
    //@RequiresPermissions("ziran:zrPaperUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZrPaperUser zrPaperUser)
    {
        startPage();
        List<ZrPaperUser> list = zrPaperUserService.selectZrPaperUserList(zrPaperUser);
        return getDataTable(list);
    }

    /**
     * 导出用户答题的试卷列表
     */
    //@RequiresPermissions("ziran:zrPaperUser:export")
    @Log(title = "用户答题的试卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZrPaperUser zrPaperUser)
    {
        List<ZrPaperUserExcel> list = zrPaperUserService.getExcelList(zrPaperUser);
        ExcelUtil<ZrPaperUserExcel> util = new ExcelUtil<ZrPaperUserExcel>(ZrPaperUserExcel.class);
        return util.exportExcel(list, "用户答题的试卷数据");
    }

    /**
     * 新增用户答题的试卷
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户答题的试卷
     */
    //@RequiresPermissions("ziran:zrPaperUser:add")
    @Log(title = "用户答题的试卷", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZrPaperUser zrPaperUser)
    {
        return toAjax(zrPaperUserService.insertZrPaperUser(zrPaperUser));
    }

    /**
     * 修改用户答题的试卷
     */
    //@RequiresPermissions("ziran:zrPaperUser:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ZrPaperUser zrPaperUser = zrPaperUserService.selectZrPaperUserById(id);
        ZrPaperUserItem pageItem=new ZrPaperUserItem();
        pageItem.setPaperUserId(zrPaperUser.getId());
        List<ZrPaperUserItem> itemList=iZrPaperUserItemService.selectZrPaperUserItemList(pageItem);
        mmap.put("zrPaperUser", zrPaperUser);
        mmap.put("itemList", itemList);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户答题的试卷
     */
    //@RequiresPermissions("ziran:zrPaperUser:edit")
    @Log(title = "用户答题的试卷", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZrPaperUser zrPaperUser)
    {
        return toAjax(zrPaperUserService.updateZrPaperUser(zrPaperUser));
    }

    /**
     * 删除用户答题的试卷
     */
    //@RequiresPermissions("ziran:zrPaperUser:remove")
    @Log(title = "用户答题的试卷", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zrPaperUserService.deleteZrPaperUserByIds(ids));
    }
}
